package tongwentongshu.com.app.presenter;

import android.content.Context;
import android.support.v4.util.ArrayMap;
import android.util.Log;

import java.util.Map;

import tongwentongshu.com.app.bean.BookSearchBean;
import tongwentongshu.com.app.contract.SearchResultContract;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.network.ResponseSubscriber;
import tongwentongshu.com.app.update.UpdateFractory;
import tongwentongshu.com.app.utils.SpUtils;

/**
 * Created by XiongBin on 2017/7/31.
 */

public class SearchResultPresenter implements SearchResultContract.Presenter {
    SearchResultContract.View searchResultView;
    private Map<String, String> map;

    public SearchResultPresenter(SearchResultContract.View searchResultView) {
        this.searchResultView = searchResultView;
    }

    @Override
    public void getSearch(Context mContext) {
        map = new ArrayMap<>();
        map.put("token", Cache.getToken());
        map.put("longitude", SpUtils.getString(mContext, Cache.LON, ""));
        map.put("latitude", SpUtils.getString(mContext, Cache.LAT, ""));
        map.put("pagesize", "50");
        map.put("bookname", searchResultView.getBookname());
        Log.e("map", map.toString());

        UpdateFractory.getBuild()
                .name("BookSearchCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<BookSearchBean>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(BookSearchBean myshare, String msg) {
                        searchResultView.onSuccess(myshare);
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }
                });
    }
}
